//
//  HSYCardInfo.m
//  HSY
//
//  Created by 陈浩 on 2017/4/24.
//  Copyright © 2017年 金开门. All rights reserved.
//

#import "HSYCardInfo.h"

static HSYCardInfo *currentShop = nil;

@implementation HSYCardInfo

+ (instancetype)sharedCardInfo {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        currentShop = [[self alloc] init];;
    });
    
    return currentShop;
}

+(id)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        currentShop = [super allocWithZone:zone];
    });
    
    return currentShop;
}

#if !__has_feature(objc_arc)

-(id)mutableCopyWithZone:(NSZone *)zone
{
    return currentUserZone;
}

-(id)copyWithZone:(NSZone *)zone
{
    return currentUserZone;
}

#endif


#pragma mark - MJExtension -
+(NSDictionary *)replacedKeyFromPropertyName{
    return @{@"cardID" : @"id"};
}

#pragma mark -AutoCoding 自动进行归档
static inline NSString * CardInfoSaveFile(){
    return [NSHomeDirectory() stringByAppendingString:@"/Documents/HSYCardInfo"];
}

+ (void)restoreCardInfo {
    NSString *path = CardInfoSaveFile();
    // 从path路径找到并解档案
    [self objectWithContentsOfFile:path];
}
+ (void)saveCardInfoToDocuments{
    NSString *path = CardInfoSaveFile();
    HSYCardInfo *shopInfo = [HSYCardInfo sharedCardInfo];
    [shopInfo writeToFile:path atomically:YES];
}

+ (void)removeSaveCardInfo{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isHave = [fileManager fileExistsAtPath:CardInfoSaveFile()];
    if (isHave) {
        [fileManager removeItemAtPath:CardInfoSaveFile() error:nil];
    }
    
    [HSYCardInfo sharedCardInfo].cardID = nil;
    [HSYCardInfo sharedCardInfo].cardAccountName = nil;
    [HSYCardInfo sharedCardInfo].idcardNO = nil;
    [HSYCardInfo sharedCardInfo].cardNO = nil;
    [HSYCardInfo sharedCardInfo].cardBank = nil;
    [HSYCardInfo sharedCardInfo].branchDistrictCode = nil;
    [HSYCardInfo sharedCardInfo].branchDistrictName = nil;
    [HSYCardInfo sharedCardInfo].bankAddress = nil;
    [HSYCardInfo sharedCardInfo].brankCode = nil;
}


@end
